package com.geek.novel.dialog

import android.content.Context
import android.graphics.drawable.ColorDrawable
import android.graphics.drawable.Drawable
import android.view.Gravity
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import com.geek.novel.R

/**
 * 确定框dialog
 */
open class ConfirmDialog(context: Context) : BaseDialog(context, R.layout.dialog_confirm) {

    private lateinit var contentTextView: TextView
    private lateinit  var btnCancel: TextView
    private lateinit  var btnConfirm: TextView
    private lateinit  var centerLine: View
    private lateinit  var btnConfirm2: TextView
    private lateinit  var centerLine2: View

    init {
        super.onCreateView()
    }

    /**绑定事件*/
    override fun bindEvent(dialogView: View) {
        //初始化对象
        contentTextView = dialogView.findViewById(R.id.tv_confirm_dialog_content)
        //取消按钮
        btnCancel = dialogView.findViewById(R.id.tv_confirm_dialog_cancel)
        //弹框的确认按钮1
        btnConfirm = dialogView.findViewById(R.id.tv_confirm_dialog_confirm)
        centerLine = dialogView.findViewById(R.id.view_confirm_block_center_line)
        btnConfirm.setOnClickListener{
            dismiss()
        }
        //弹框的确认按钮2
        btnConfirm2 = dialogView.findViewById(R.id.tv_confirm_dialog_confirm_2)
        centerLine2 = dialogView.findViewById(R.id.view_confirm_block_center_line_2)

        //取消按钮的事件
        btnCancel.setOnClickListener {
            dismiss()
        }
    }

    /**设置弹框显示隐藏的动画效果*/
    override fun animationStyle(): Int = R.style.dialog_anim_style_menu_list

    /**事件确认按钮点击事件*/
    open fun setOnConfirmListener(confirm: String, listener: View.OnClickListener){
        btnConfirm.text = confirm
        btnConfirm.setOnClickListener(listener)
    }

    /**事件确认按钮2点击事件*/
    open fun setOnConfirm2Listener(confirm: String, listener: View.OnClickListener){
        btnConfirm2.visibility = View.VISIBLE
        centerLine2.visibility = View.VISIBLE
        btnConfirm2.text = confirm
        btnConfirm2.setOnClickListener(listener)
    }

    /**隐藏事件确认按钮2*/
    open fun hideConfirm2Btn(){
        btnConfirm2.visibility = View.GONE
        centerLine2.visibility = View.GONE
    }

    /**隐藏取消按钮*/
    fun hideDismissBtn(){
        this.setDismissBtnVisible(View.GONE)
    }

    /**显示取消按钮*/
    fun showDismissBtn(){
        this.setDismissBtnVisible(View.VISIBLE)
    }

    /**隐藏取消按钮*/
    private fun setDismissBtnVisible(visible: Int){
        btnCancel.visibility = visible
        centerLine.visibility = visible
    }

    open fun openDialog(text: String){
        contentTextView.text = text
        super.openDialog(Gravity.CENTER)
    }

    open fun openDialog(text: String, listener: View.OnClickListener){
        this.setOnConfirmListener("确定", listener)
        this.openDialog(text)
    }

    open fun openDialog(text: String, confirm: String, listener: View.OnClickListener){
        this.setOnConfirmListener(confirm, listener)
        this.openDialog(text)
    }

}